package com.rede.didiok.user.modulelist.community.web;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.community.UserMomentTopicDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;
import com.rede.didiok.user.modulelist.community.service.UserMomentTopicService;

// import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 用户话题表
 *
 * @author Rede
 * @email didiok@foxmail.com
 * @date 2023-09-06 18:35:22
 */
@Slf4j
@RestController
@RequestMapping("community/feign/userMomentTopic")
public class UserMomentTopicController {
    @Autowired
    private UserMomentTopicService userMomentTopicService;

    @ApiOperation(value = "获取用户动态话题列表", notes = "获取用户动态话题列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户动态话题列表");
        return ResultUtil.successWithData(userMomentTopicService.getPageList(userMomentTopicDto));
    }

    @AvoidRepeatableCommit
    @ApiOperation(value = "增加用户动态话题", notes = "增加用户动态话题", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("增加用户动态话题");
        return userMomentTopicService.addUserMomentTopic(userMomentTopicDto);
    }

    @ApiOperation(value = "编辑用户动态话题", notes = "编辑用户动态话题", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑用户动态话题");
        return userMomentTopicService.editUserMomentTopic(userMomentTopicDto);
    }

    @ApiOperation(value = "批量删除用户动态话题", notes = "批量删除用户动态话题", response = String.class)
    @PostMapping("/deleteBatch")
    public String delete(@Validated({Delete.class}) @RequestBody List<UserMomentTopicDto> userMomentTopicDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("批量删除用户动态话题");
        return userMomentTopicService.deleteBatchUserMomentTopic(userMomentTopicDtoList);
    }
}
